<template>
  <div>
    <div class="ui-scrollview">
      <div class="a-wrap-item" v-if="!isToken">
        <div class="top">
          <img src="@/assets/image/avatar.png" alt="" />
          <div>
            <p>欢迎来到BC.GAME</p>
            <span>请先注册或登录</span>
          </div>
        </div>
        <div class="btn-box">
          <button class="login-btn" @click="login">登录</button>
          <button class="register-btn" @click="login">注册</button>
        </div>
      </div>
      <div class="a-wrap-item" v-if="user">
        <div class="top">
          <img src="@/assets/image/avatar-default.png" alt="" />
          <div>
            <p>{{ user.nickName }}</p>
            <span>{{ user.mobile }}</span>
          </div>
        </div>
      </div>
      <div class="list">
        <div class="item">
          <div class="left">
            <img src="" alt="" />
            <p>语言</p>
          </div>
          <div class="right">
            <p>汉语</p>
            <img src="" alt="" />
          </div>
        </div>
        <div class="item">
          <div class="left">
            <img src="" alt="" />
            <p>货币</p>
          </div>
          <div class="right">
            <img src="" alt="" />
          </div>
        </div>
      </div>
      <button class="submit" @click="logout" v-if="isToken">退出登录</button>
    </div>
  </div>
</template>
<script setup>
  import { computed, onMounted, ref } from 'vue';
  import { useStore } from 'vuex';
  import { userInfo } from '@/api/index';
  import { ElMessageBox } from 'element-plus';
  import { useRouter } from 'vue-router';
  const router = useRouter();
  const store = useStore();
  const user = ref();
  const isToken = computed(() => {
    return store.getters['user/accessToken'];
  });
  onMounted(async () => {
    const res = await userInfo();
    user.value = res.data.data;
    console.log(user.value);
  });
  const logout = () => {
    ElMessageBox.confirm(`是否退出登录`, '提示', {
      dangerouslyUseHTMLString: true,
      type: 'warning',
    })
      .then(() => {
        store.dispatch('user/logout');
      })
      .catch(() => {});
  };
  const login = () => {
    router.replace('/mobileLogin');
  };
</script>

<style lang="scss" scoped>
  .ui-scrollview {
    padding: 1rem 0.75rem;
    .a-wrap-item {
      margin-bottom: 1rem;
      background: #2e3035;
      border-radius: 0.25rem;
      padding: 1rem 0.75rem;
      .top {
        display: flex;
        align-items: center;
        img {
          display: block;
          width: 4rem;
          height: 4rem;
        }
        div {
          margin-left: 1rem;
          p {
            color: #fff;
            font-size: 1.125rem;
            font-weight: 700;
          }
          span {
            font-size: 0.875rem;
            color: #98a7b5;
            margin-top: 0.25rem;
          }
        }
      }
      .btn-box {
        margin-top: 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .login-btn {
          background: #3c404a;
          width: 48%;
          height: 2.75rem;
          color: #fff;
          border-radius: 0.25rem;
          font-weight: 700;
          font-size: 0.875rem;
        }
        .register-btn {
          background-color: #1d803ab3;
          background-image: conic-gradient(from 1turn, rgba(88, 175, 16, 1), rgba(29, 128, 58, 1));
          width: 48%;
          height: 2.75rem;
          color: #fff;
          border-radius: 0.25rem;
          font-weight: 700;
          font-size: 0.875rem;
        }
      }
    }
    .list {
      background: #2e3035;
      .item {
        height: 3.25rem;
        margin: 0.125rem 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 0.75rem;
        border-radius: 0.25rem;
        .left {
          display: flex;
          align-items: center;
          img {
            display: block;
            width: 1.5rem;
            height: 1.5rem;
            background: #f00;
            border-radius: 50%;
          }
          p {
            font-size: 1rem;
            margin-left: 0.75rem;
            color: #fff;
            opacity: 0.9;
          }
        }
        .right {
          display: flex;
          align-items: center;
          img {
            display: block;
            width: 1.5rem;
            height: 1.5rem;
            background: #f00;
            border-radius: 50%;
          }
          p {
            color: #98a7b5;
            font-size: 1rem;
            margin-right: 0.75rem;
          }
        }
      }
    }
    .submit {
      padding: 0 0.75rem;
      height: 3rem;
      background: #f00;
      border-radius: 1rem;
      margin-top: 4rem;
      color: #fff;
      font-size: 1rem;
      font-weight: 500;
      line-height: 3rem;
      display: block;
      width: 100%;
    }
  }
</style>
